package dmwr.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import dmwr.Dmwr;
import dmwr.bean.User;

public class StartupAndShutdown implements ServletContextListener {

	private static final byte[] PASSWORD_HASH = new byte[] { -19, 85, -22, 64,
			31, 20, -89, -47, -46, 85, -92, -18, 23, 11, 5, -27, -39, -73, 78,
			98, 35, 101, -98, 104, -106, -116, 9, -59, 35, -56, 83, -113 };
	private static final byte[] PASSWORD_SALT = new byte[] { -127, 44, -30, 5,
			-80, -16, -14, -106, -89, -108, -118, -1, -69, -25, 78, -32 };

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		Dmwr.service().createUserIfFirst(
				new User(null, "diego.schivo", PASSWORD_HASH, PASSWORD_SALT,
						null, null, null));
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
	}

	// private static String foo(byte[] bb) {
	// StringBuilder sb = new StringBuilder();
	// for (byte b : bb) {
	// if (sb.length() > 0) {
	// sb.append(',');
	// }
	// sb.append(b);
	// }
	// return "{" + sb + "}";
	// }
}
